// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void showtime (DateTime *n)
{
    Serial.print(n->year(), DEC);
    Serial.print('/');
    Serial.print(n->month(), DEC);
    Serial.print('/');
    Serial.print(n->day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[n->dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(n->hour(), DEC);
    Serial.print(':');
    Serial.print(n->minute(), DEC);
    Serial.print(':');
    Serial.print(n->second(), DEC);
    Serial.println();
}


void setup () {
  while (!Serial) continue;
  Serial.begin(9600);
  delay(3000); // wait for console opening

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1) continue;
  }

  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  DateTime now = rtc.now();
  DateTime future = now + TimeSpan(0,0,1,0);

  Serial.print ("RTC currently...      ");
  showtime (&now);

  Serial.print ("Hi any key when it's: ");
  showtime (&future);
  while (Serial.available() < 1) continue;
  rtc.adjust(future);
}

void loop () {
  delay(3000);
  DateTime now = rtc.now();
  showtime (&now);
  Serial.println();
}
